package com.talent.web.config.security;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpMethod;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
/**
 * @Author: hszhou
 * @Date: 2024/10/21 13:35
 * @Description:  白名单
 */
@Data
@Component
@ConfigurationProperties(prefix = "white-list")
public class WhiteListProperties {

    private List<String> gets;

    private List<String> posts;


    public RequestMatcher[] getRequestMatchers() {
        List<RequestMatcher> requestMatchersList = new ArrayList<>();
        gets.stream().map(url->new AntPathRequestMatcher(url, HttpMethod.GET.name())).forEach(requestMatchersList::add);
        posts.stream().map(url->new AntPathRequestMatcher(url, HttpMethod.POST.name())).forEach(requestMatchersList::add);
        return requestMatchersList.toArray(new RequestMatcher[0]);
    }
}
